#include "MainMenuState.h"
#include "ServerMenuState.h"
#include "ClientMenuState.h"
#include "SettingsMenuState.h"
#include "GamePlayState.h"
#include "Client.h"
#include "NetworkException.h"
#include "EventWrapper.h"

MainMenuState::MainMenuState()
    : MenuState("Main Menu")
{
}

void MainMenuState::addMenuLines()
{
    addLine("1. Start server");
    addLine("2. Join server");
    addLine("3. Settings");
    addLine("ESC. Quit");
}

GameState* MainMenuState::performMenuAction1()
{
    return goToNextState(new ServerMenuState());
}

GameState* MainMenuState::performMenuAction2()
{
    ClientPtr client(new Client());
    try
    {
        client->start();
        return goToNextState(new ClientMenuState(client));
    }
    catch (NetworkException& e)
    {
        return this;
    }
}

GameState* MainMenuState::performMenuAction3()
{
    return goToNextState(new SettingsMenuState());
}

GameState* MainMenuState::performMenuActionEscape()
{
    EventWrapper::pushQuit();
    return this;
}

MainMenuState::~MainMenuState()
{
}
